
public class Main {
    public static void main(String[] args) {

        var res1 = Result.Ok(2).map(x -> x * 2);
        System.out.println(res1.unwrap());

        var res2 = Result.Err(StateCode.NotFound).mapErr(e -> 404);
        System.out.println(res2);

        var res3 = Result.Ok(1)
            .andThen(x -> 
                Result.Ok(2)
                    .andThen(y -> Result.Ok(x + y))
        );

        System.out.println(res3);
    }
}


enum StateCode {
    NotFound() {
        @Override
        public String toString() {
            return "404 not found";
        }
    },
    Forbidden() {
        @Override
        public String toString() {
            return "403 Forbidden";
        }
    }
}